package com.ehome.poct.base.controller.device;

import com.ehome.core.page.PageInfo;
import com.ehome.poct.base.api.dto.device.DeviceQry;
import com.ehome.poct.base.api.dto.device.bootModule.BootInfoDTO;
import com.ehome.poct.base.api.dto.device.bootModule.TestDeviceBootingHistDTO;
import com.ehome.poct.base.api.virtual.device.TestDeviceBootingDetailService;
import com.ehome.poct.base.api.virtual.device.TestDeviceBootingHistService;
import com.ehome.poct.base.api.vo.device.BootInfoVO;
import com.ehome.poct.base.api.vo.device.TestDeviceBootingHistVO;
import com.ehome.web.controller.AbstractBaseController;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * 设备开机自检记录控制器
 *
 * @author laobai
 * @Date 2022-10-14 17:38
 */
@Slf4j
@Api(tags = "设备开机自检记录")
@RestController
@AllArgsConstructor
@RequestMapping("/devicebootinghist")
public class TestDeviceBootingHistController extends AbstractBaseController<TestDeviceBootingHistVO, TestDeviceBootingHistDTO> {
    private final TestDeviceBootingDetailService testDeviceBootingDetailService;
    private final TestDeviceBootingHistService testDeviceBootingHistService;

    /**
     * 添加开机自检详细
     * @param reqDto 开机自检信息
     * @return true 已录入 false 失败
     */
    @ApiOperation("添加设备自检记录")
    @ApiOperationSupport(author = "laobai")
    @PostMapping("/addBootInfo")
    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = {Exception.class})
    public Boolean addBootInfo(@RequestBody BootInfoDTO reqDto){
        var his =testDeviceBootingHistService.insert(reqDto.getHistDTO());
        var detail = testDeviceBootingDetailService.insert(reqDto.getDetailDTO());
        return null!=his&&null!=detail;
    }

    /**
     * 获取设备开机记录统计列表信息
     * @param qry 查询条件
     * @return 含分页信息 开机自检概述 几大模块的状态
     */
    @ApiOperation("获取开机自检详细")
    @ApiOperationSupport(author = "laobai")
    @PostMapping("/getsnodetaillist")
    public PageInfo<TestDeviceBootingHistVO> getSnoDetailList(@RequestBody DeviceQry qry){
        return testDeviceBootingHistService.getSnoDetailList(qry);
    }
    /**
     * 获取设备开机记录统计列表信息
     * @param qry 查询条件 sno和时间
     * @return 设备的开机自检统计信息 分页
     */
    @ApiOperation("获取设备开机记录统计列表信息")
    @ApiOperationSupport(author = "laobai")
    @PostMapping("/getallinfo")
    PageInfo<BootInfoVO> getAllBootInfo(@RequestBody DeviceQry qry){
        return testDeviceBootingHistService.getAllBootInfo(qry);
    }
}
